{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(200L, 2L)\n"
     ]
    }
   ],
   "source": [
    "#介绍CART(classification and regression tree)分类回归树\n",
    "\n",
    "#先介绍，决策树对于连续性数值的回归问题————回归树\n",
    "#1，切分数据：二元切分法，x>a和x<=a,其中的a属于某个特征xi的所有取值集合\n",
    "#2,选择特征：选择使得，切分数据的总均方差最小\n",
    "#3,预测：使用切分数据集的平均值，代表预测值\n",
    "\n",
    "#先导入数据\n",
    "import numpy as np\n",
    "def loadDataSet(fileName):      \n",
    "    dataMat = []                #assume last column is target value\n",
    "    fr = open(fileName)\n",
    "    for line in fr.readlines():\n",
    "        curLine = line.strip().split('\\t')\n",
    "        floatLine = map(float,curLine) #map all elements to float()\n",
    "        dataMat.append(floatLine) #这里把最后一列作为目标变量，y\n",
    "    return np.mat(dataMat)\n",
    "\n",
    "myData= loadDataSet('regressionTree/ex00.txt')\n",
    "print myData.shape\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY4AAAEKCAYAAAAFJbKyAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3W2MHVd5B/D/s2uv6MZRSa5DSKG7G1D6ElpA8TYNUYQC\npSW4ldKXfAhdBYqQVl4EykdCXUFF60L51FAIYNFQmt2CKkrBpQ4IgtrQUiBrlDihNGBo1oSGJjFV\nomCq2PHTD3Mvez2el3Nmzjlzzsz/J43W9965M2d2rfPMOec5Z0RVQUREZGqm6wIQEVFaGDiIiMgK\nAwcREVlh4CAiIisMHEREZIWBg4iIrDBwEBGRFQYOIiKywsBBRERWdnRdAB92796tS0tLXReDiCgZ\nR44ceVxVLzLZt5eBY2lpCZubm10Xg4go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gD/B+BqVX2m4yIRNcauKqIwRsgeJHQ+spYH\nUbLY4iBt0WPUAAAAaUlEQVQKQEQOIXtC3aUALlHVN3dcJKLGBr06LlEI46fsnVLVvxWRWQBfFpFX\nquoXuy4bURNscRARkRWOcRARkRUGDiIissLAQUREVhg4iIjICgMHERFZYeAgIiIrDBxERGSFgYOI\niKz8Pw+3C5iP74IJAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x791ef60>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#可视化一下ex00.txt的数据\n",
    "import matplotlib.pyplot as plt\n",
    "plt.scatter(myData[:,0].A,myData[:,1].A,color=\"blue\") #np.matrix.A--->matrix转化为array\n",
    "plt.xlabel(\"x\")\n",
    "plt.ylabel(\"y\")\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(116L, 2L) (84L, 2L)\n"
     ]
    }
   ],
   "source": [
    "#二元切分法,x>a和x<=a,其中的a属于某个特征xi的所有取值集合\n",
    "#notice:切分的特征并没有删除，这与前面ID3算法的决策树分类中，切分数据不同!!!\n",
    "\n",
    "def binSplitDataSet(dataSet, feature, value):\n",
    "    mat0 = dataSet[np.nonzero(dataSet[:,feature] > value)[0],:]\n",
    "    mat1 = dataSet[np.nonzero(dataSet[:,feature] <= value)[0],:]\n",
    "    return mat0,mat1\n",
    "#测试一下\n",
    "mat0,mat1 = binSplitDataSet(myData,0,0.5)\n",
    "print mat0.shape,mat1.shape\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "#树回归的叶子节点————数据集合中y的均值\n",
    "def regLeaf(dataSet):\n",
    "    return np.mean(dataSet[:,-1])\n",
    "\n",
    "#用y的总均方差代表连续型数据的混乱度\n",
    "def regErr(dataSet):\n",
    "    return np.var(dataSet[:,-1]) * np.shape(dataSet)[0] #总均方差=均方差*num\n",
    "\n",
    "#选择合适的特征划分:返回最好的特征bestIndex,和对应的值bestValue\n",
    "\n",
    "def chooseBestSplit(dataSet, leafType=regLeaf, errType=regErr, ops=(1,4)):\n",
    "    tolS = ops[0] #均方差变化的最小幅度，用于预剪枝\n",
    "    tolN = ops[1] #划分的数据集的最小size\n",
    "   \n",
    "    if len(set(dataSet[:,-1].T.tolist()[0])) == 1: #exit condition 1:\n",
    "        # 如果所有的y的值都相等，这里用set去重,直接返回叶子节点，不做划分\n",
    "        return None, leafType(dataSet) #直接返回\n",
    "    m,n = np.shape(dataSet) #数据集合大小\n",
    "    #the choice of the best feature is driven by Reduction in RSS error from mean\n",
    "    S = errType(dataSet) #原来数据集合的总均方差\n",
    "    bestS = np.inf\n",
    "    bestIndex = 0\n",
    "    bestValue = 0\n",
    "    for featureIndex in range(n-1): #遍历每一个特征：因为下标-1是y的值，不是特征\n",
    "        for splitVal in set(dataSet[:,featureIndex].A.ravel()): #遍历当前特征的每一个取值\n",
    "            mat0, mat1 = binSplitDataSet(dataSet, featureIndex, splitVal)\n",
    "            if (np.shape(mat0)[0] < tolN) or (np.shape(mat1)[0] < tolN): \n",
    "                #如果划分之后的数据集合size太小了，直接跳过，不划分\n",
    "                continue\n",
    "            newS = errType(mat0) + errType(mat1) #划分之后的两个小数据集合的总均方差\n",
    "            if newS < bestS:  #选出最优值\n",
    "                bestIndex = featureIndex\n",
    "                bestValue = splitVal\n",
    "                bestS = newS\n",
    "    #if the decrease (S-bestS) is less than a threshold,don't do the split\n",
    "    if (S - bestS) < tolS:\n",
    "        #误差变化的幅度太小，直接返回叶子节点，不做划分\n",
    "        return None, leafType(dataSet) #exit condition 2 #退出条件2\n",
    "    mat0, mat1 = binSplitDataSet(dataSet, bestIndex, bestValue) #最优的划分子集合\n",
    "    if (np.shape(mat0)[0] < tolN) or (np.shape(mat1)[0] < tolN):  #exit condition 3\n",
    "        #划分的子集合太小,直接返回叶子节点，不做划分\n",
    "        return None, leafType(dataSet)\n",
    "    return bestIndex,bestValue#returns the best feature to split on\n",
    "                              #and the value used for that split\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'spInd': 0, 'spVal': 0.48813000000000001, 'right': -0.044650285714285719, 'left': 1.0180967672413792}\n"
     ]
    }
   ],
   "source": [
    "#用一个全局变量，来保存最优的划分数据\n",
    "bestFeatures=[]\n",
    "bestValues=[]\n",
    "\n",
    "\n",
    "#递归创建回归树\n",
    "def createTree(dataSet, leafType=regLeaf, errType=regErr, ops=(1,4)):\n",
    "    #assume dataSet is NumPy Mat so we can array filtering\n",
    "    feature, val = chooseBestSplit(dataSet, leafType, errType, ops)#choose the best split\n",
    "    if feature == None: #如果返回的是没有划分，和叶子节点的值\n",
    "        return val #if the splitting hit a stop condition return val\n",
    "    retTree = {}\n",
    "    retTree['spInd'] = feature\n",
    "    retTree['spVal'] = val\n",
    "    \n",
    "    bestFeatures.append(feature)#保存下来\n",
    "    bestValues.append(val)\n",
    "    \n",
    "    lSet, rSet = binSplitDataSet(dataSet, feature, val) #分成左右两个子树\n",
    "    retTree['left'] = createTree(lSet, leafType, errType, ops)\n",
    "    retTree['right'] = createTree(rSet, leafType, errType, ops)\n",
    "    \n",
    "    return retTree  \n",
    "\n",
    "#测试一下\n",
    "myData= loadDataSet('regressionTree/ex00.txt')\n",
    "myTree = createTree(myData)\n",
    "print myTree\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY4AAAEKCAYAAAAFJbKyAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3W2QJVV5B/D/w+wOMqIR7q5IwJlFCzWQCMVOCKEoZ31J\n1NUq8sIHyIAbtGpqh9JavonZlFYl2c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qnd8clakL/LnsvqOrficgYgLtF5C2q+q22y0ZUBnsc\nRETkhDkOIiJywsBBREROGDiIiMgJAwcRETlh4CAiIicMHERE5ISBg4iInDBwEBGRk/8DosZ6+6al\nS2sAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7cb2400>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#可视化一下ex00.txt数据集的划分界限\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "plt.scatter(myData[:,0].A,myData[:,1].A,color=\"blue\")\n",
    "\n",
    "y = myData[:,-1].A\n",
    "y_min = np.min(y) - 0.1\n",
    "y_max = np.max(y) + 0.1\n",
    "y_val = np.arange(y_min,y_max,0.01)\n",
    "for i in xrange(len(bestValues)):\n",
    "    plt.plot([bestValues[i]]*y_val.shape[0],y_val,color=\"black\") #画出那条分界线\n",
    "plt.xlabel(\"x\")\n",
    "plt.ylabel(\"y\")\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(200L, 3L)\n{'spInd': 1, 'spVal': 0.39434999999999998, 'right': {'spInd': 1, 'spVal': 0.19783400000000001, 'right': -0.023838155555555553, 'left': 1.0289583666666666}, 'left': {'spInd': 1, 'spVal': 0.58200200000000002, 'right': 1.980035071428571, 'left': {'spInd': 1, 'spVal': 0.79758300000000004, 'right': 2.9836209534883724, 'left': 3.9871631999999999}}}\n"
     ]
    }
   ],
   "source": [
    "#测试一下ex0.txt数据集\n",
    "\n",
    "\n",
    "bestFeatures = [] #先清空一下list,注意python2没有clear（）\n",
    "bestValues = []\n",
    "\n",
    "myData= loadDataSet('regressionTree/ex0.txt')\n",
    "print myData.shape\n",
    "myTree = createTree(myData)\n",
    "print myTree\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0.39434999999999998, 0.58200200000000002, 0.79758300000000004, 0.19783400000000001]\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAEKCAYAAAARnO4WAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAH5xJREFUeJzt3X+MHGd5B/Dvc2ef7YvTEu9drSjhzi6/2giVQK/UIqhJ\ngyqCi4pa8Qd0fXHjSCa+ghypUqG9qvxRrr/+qHDV2pEJhou9JaKAaIrSIlCI0wpMc2lDIKRASnwm\nlDr2uq1xnObO56d/vDvaudl5Z96ZnZndmfl+pJPv9mZ3ZhznmXeeed7nFVUFERFV38igD4CIiIrB\ngE9EVBMM+ERENcGAT0RUEwz4REQ1wYBPRFQTDPhERDXBgE9EVBMM+ERENbFh0AfgNzExoTt27Bj0\nYRARlcYTTzxxXlUnXbYdqoC/Y8cOLC0tDfowiIhKQ0SWXbdlSoeIqCYY8ImIaoIBn4ioJhjwiYhq\nggGfiKgmGPCJiGqCAZ+IqCYY8Evq3nvvxb333jvowyhE1c+16ufngn8HxRiqiVfk7sknnxz0IRSm\n6uda9fNzwb+DYnCET0Sl0WoBO3YAIyPmz1Zr0EdULhzhE1EptFrA/v3A5cvm5+Vl8zMANJuDO64y\n4QifiEphfr4b7D2XL5vXyQ0DPhGVwpkzyV6nXgz4RFQKU1PJXqdeDPhEVAoLC8D4+PrXxsfN6+SG\nAZ+ISqHZBI4eBaanARHz59Gj9ge2rOjpxSodIiqNZtOtIocVPeE4wieiyrFV9OzZU+/RPgM+EVVO\nVOWON9pPG/TLnCpiwCeiyomr3Elbv++lipaXAdX+Lx5FY8AnosoJq+gJSlO/X/bJXwz4RFQ5/ooe\nmzT1+1lM/hpkSogBn4hKKS5wNpvA6dPAiRPZ1e/3O/lr0CkhBnwiKp0kgTNp/X7UPi9d6n09ycVj\n0CkhBnwiKp2kgdMb7V+9av50DfbeXYQIMDsLtNvrf99o2C8e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qoi1VYvCrdCF9Vr4jI+wF8EeaJ/zFVfVpE7un8/j6Yyo3dAJ4FcBlmxFBKjuf7hwAaAA53\nRr1XtKQNqBzPtzJczldVnxGRfwTwFICrAO5X1dASv2Hn+N/3jwB8UkS+CVO58kFVLW0HTRH5FIDb\nAEyIyPMAPgxgI1B8vOJMWyKimihjSoeIiFJgwCciqgkGfCKimmDAJyKqCQZ8IqKaYMAnIqoJBnwi\noppgwCey6PTbf0pENovINZ3e7K8f9HERpcWJV0QRROQjADbDNC17XlX/ZMCHRJQaAz5RhE6/l8cB\n/B+At6jq2oAPiSg1pnSIojVgFuG4FmakT1RaHOETRRCRh2BWZdoJ4HpVff+AD4kotdJ1yyQqSmdl\nqVVV/RsRGQXwVRG5XVUfGfSxEaXBET4RUU0wh09EVBMM+ERENcGAT0RUEwz4REQ1wYBPRFQTDPhE\nRDXBgE9EVBMM+ERENfH/8xjedX5M40sAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7eab160>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#可视化一下ex0.txt数据集的划分界限\n",
    "print bestValues\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "plt.scatter(myData[:,1].A,myData[:,-1].A,color=\"blue\")\n",
    "\n",
    "y = myData[:,-1].A\n",
    "y_min = np.min(y) - 0.1\n",
    "y_max = np.max(y) + 0.1\n",
    "y_val = np.arange(y_min,y_max,0.01)\n",
    "for i in xrange(len(bestValues)):\n",
    "    plt.plot([bestValues[i]]*y_val.shape[0],y_val,color=\"black\")\n",
    "plt.xlabel(\"x\")\n",
    "plt.ylabel(\"y\")\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "#接下来，构建模型树————即，叶子节点存放的不是数据集合的均值，而是数据集合的线性方程\n",
    "#最佳划分的判断：选择线性方程拟合的误差最小的划分方法\n",
    "\n",
    "def linearSolve(dataSet):   #在线性回归中，用到的求解最优w的公式\n",
    "    m,n = np.shape(dataSet)\n",
    "    X = np.mat(np.ones((m,n)))\n",
    "    Y = np.mat(np.ones((m,1)))#create a copy of data with 1 in 0th postion\n",
    "    X[:,1:n] = dataSet[:,0:n-1] #注意，这里，只改变了1-(n-1)维度的数据，因为x0=1\n",
    "    Y = dataSet[:,-1]#and strip out Y\n",
    "    xTx = X.T*X\n",
    "    if np.linalg.det(xTx) == 0.0:\n",
    "        raise NameError('This matrix is singular, cannot do inverse,\\n\\\n",
    "        try increasing the second value of ops')\n",
    "    ws = xTx.I * (X.T * Y)\n",
    "    return ws,X,Y\n",
    "\n",
    "def modelLeaf(dataSet):#模型树的叶子节点返回的是：线性方程的系数\n",
    "    ws,X,Y = linearSolve(dataSet)\n",
    "    return ws\n",
    "\n",
    "def modelErr(dataSet): #返回总的误差，用于判断划分的好坏\n",
    "    ws,X,Y = linearSolve(dataSet)\n",
    "    yHat = X * ws\n",
    "    return np.sum(np.power(Y - yHat,2))\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(200L, 2L)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEKCAYAAAAfGVI8AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAGcdJREFUeJzt3XuMXGd5x/Hfs+tdkbEDiWe3ESX1bEpooEpBJduWUkRT\nkorgRk0v/AFdOyZBWtkrqFWpKrSuyh/tFkr7R10h21olNsY7DWpTWlIElCiIpiqEsi4hCQmFFOwl\nXBp7DS3JtvXt6R/vnO54PJczl3POzDnfjzTanZkze94jJ+eZ93nei7m7AADFNZZ1AwAA2SIQAEDB\nEQgAoOAIBABQcAQCACg4AgEAFByBAAAKjkAAAAVHIACAgtuUdQPimJqa8pmZmaybAQAj5fjx46fd\nfbrTc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nbFzSZ83sDe7+6azbBnSLHgEAFBw1AgAoOAIBABQcgQAACo5AAAAFRyAAgIIjEABAwREIAKDgCAQA\nUHD/Bz+pK1fldSAQAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x86b3470>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#先导入数据集合，并且可视化一下\n",
    "\n",
    "myData2 = loadDataSet('regressionTree/exp2.txt')\n",
    "print myData2.shape\n",
    "plt.scatter(myData2[:,0].A,myData2[:,-1].A,color=\"blue\")\n",
    "plt.xlabel(\"x\")\n",
    "plt.ylabel(\"y\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'spInd': 0, 'spVal': 0.28547699999999998, 'right': matrix([[ 3.46877936],\n        [ 1.18521743]]), 'left': matrix([[  1.69855694e-03],\n        [  1.19647739e+01]])}\n[0.28547699999999998]\n[0]\n"
     ]
    }
   ],
   "source": [
    "#现在利用上面的数据，生成模型树\n",
    "\n",
    "bestFeatures = [] #先清空一下list,注意python2没有clear（）\n",
    "bestValues = []\n",
    "myModelTree = createTree(myData2,leafType=modelLeaf,errType=modelErr,ops=(1,10))\n",
    "print myModelTree\n",
    "\n",
    "print bestValues\n",
    "print bestFeatures\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEKCAYAAAAfGVI8AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAGfdJREFUeJzt3X2QZFdZx/Hfs7M7QGdTEnpGCsHtiYCAhRjJqhEtiESL\nsFKCyh/ozLLZULW1MyVurLIEHEv+0PEF/YO1qE3cgt1sdq9QGlHRigglFbDkRSYaIRAVhJ0Q3jLZ\ntZSwwr7M4x+nr9P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0oyZPSrprZJ2\nSflfq6gsBoCaq9rQEAAgJQIBANQcgQAAao5AAAA1RyAAgJojEABAzREIAKDmCATACNr7HXzKzJ5s\nZte018Z/YdHtAkZBQRkwIjP7bUlPVljs7VF3/92CmwSMhEAAjKi9Hs4nJX1L0kvc/UrBTQJGwtAQ\nMLqmwuYo1yr0DIBSokcAjMjM3qewi9b1kp7h7r9UcJOAkVRq9VEgL+2dwC65+5+Y2ZSkj5rZy939\nQ0W3DUiLHgEA1Bw5AgCoOQIBANQcgQAAao5AAAA1RyAAgJojEABAzREIAKDmCAQAUHP/BwbQxFG5\nQK4vAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x86c97f0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#可视化一下exp.txt数据集的划分界限\n",
    "\n",
    "\n",
    "plt.scatter(myData2[:,0].A,myData2[:,1].A,color=\"blue\")\n",
    "\n",
    "y = myData2[:,-1].A\n",
    "y_min = np.min(y) - 0.1\n",
    "y_max = np.max(y) + 0.1\n",
    "y_val = np.arange(y_min,y_max,0.01)\n",
    "for i in xrange(len(bestValues)):\n",
    "    plt.plot([bestValues[i]]*y_val.shape[0],y_val,color=\"black\") #画出那条分界线\n",
    "plt.xlabel(\"x\")\n",
    "plt.ylabel(\"y\")\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "#最后看看怎么进行预测\n",
    "\n",
    "#判断是不是树，也就是字典\n",
    "def isTree(obj):\n",
    "    return (type(obj).__name__=='dict')\n",
    "\n",
    "#回归树，直接返回叶子节点的值：小数据集合的均值\n",
    "def regTreeEval(leaf, inData):\n",
    "    return float(leaf)\n",
    "\n",
    "#模型树，返回线性方程的值\n",
    "def modelTreeEval(leaf, inData):\n",
    "    n = np.shape(inData)[1]\n",
    "    X = np.mat(np.ones((1,n+1))) #x0=1\n",
    "    X[:,1:n+1] = inData\n",
    "    return float(X*leaf)\n",
    "\n",
    "#树的递归预测\n",
    "def treeForeCast(tree, inData, modelEval=regTreeEval):\n",
    "    if not isTree(tree): #如果不是树，叶子节点，则返回预测值\n",
    "        return modelEval(tree, inData)\n",
    "    if inData.A.ravel()[tree['spInd']] > tree['spVal']: #大于特征值，则是左子树\n",
    "        if isTree(tree['left']): #如果是树，继续递归\n",
    "            return treeForeCast(tree['left'], inData, modelEval) #递归\n",
    "        else: #如果是叶子节点，直接返回预测值\n",
    "            return modelEval(tree['left'], inData)\n",
    "    else: #小于等于则是右子树\n",
    "        if isTree(tree['right']): \n",
    "            return treeForeCast(tree['right'], inData, modelEval)\n",
    "        else: \n",
    "            return modelEval(tree['right'], inData)\n",
    "\n",
    "#利用生成的树，进行预测\n",
    "def createForeCast(tree, testData, modelEval=regTreeEval):\n",
    "    m=len(testData)\n",
    "    yHat = np.mat(np.zeros((m,1)))\n",
    "    for i in range(m):\n",
    "        yHat[i,0] = treeForeCast(tree, np.mat(testData[i]), modelEval) #递归预测\n",
    "    return yHat\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(200L, 1L)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEKCAYAAAAfGVI8AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xl8VPW9//HXZyYhiALSiMGNuiBacblUCkQUI6BQ0CCC\nXlwaEREEQfBxRYvWCnWhV7EXdwgKGqioFVKVH4IQTUAcQaiWiop1oWKREKC4km3m+/vjZEiILAkk\ns76fj0ceycyc5HzPAz3v893NOYeIiCQvX7QLICIi0aUgEBFJcgoCEZEkpyAQEUlyCgIRkSSnIBAR\nSXIKAhGRJKcgEBFJcgoCEZEklxLtAtTFEUcc4Y4//vhoF0NEJK6sWbNmq3Ou9f6Oi4sgOP7441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YH3gR7AScASM1vunPs2usWKX4kSBP8G\njqvx+tiq9+p7TDyp0/WY2ZnAU8CvnXPbIlS2xlCX6+0EPF8VAkcAfc2s0jn318gUscHV5Zq/ArY5\n534AfjCzZcBZQLwGQV2u+Trgj85rQP/UzL4ATgVWRaaIEdfo965EaRp6FzjZzE4wsybAYOCVWse8\nAuRU9cB3Bb5xzn0d6YI2oP1es5m1BeYDv0mAJ8T9Xq9z7gTn3PHOueOBl4BRcRwCULf/rl8GzjWz\nFDNrBnQBPopwORtSXa75S7waEGaWAZwCfB7RUkZWo9+7EqJG4JyrNLPRwGK8UQcznXPrzOzGqs+n\n4Y0i6Qt8CvyI91QRt+p4zb8H0oEnqp6SK12cLtpVx+tNKHW5ZufcR2a2CFgLhICnnHN7HIYYD+r4\n73wP8IyZ/QNvJM3tzrm4XZXUzOYCWcARZvYVcDeQCpG7d2lmsYhIkkuUpiERETlACgIRkSSnIBAR\nSXIKAhGRJKcgEBFJcgoCEZEkpyAQEUlyCgKRA1C158FaM2tqZodWrYt/erTLJXIgNKFM5ACZ2b1A\nU7zF3r5yzk2OcpFEDoiCQOQAVa2F8y5QCpzjnAtGuUgiB0RNQyIHLh1vY5TmeDUDkbikGoHIATKz\nV/B20DoBOMo5NzrKRRI5IAmx+qhIpFXtBFbhnHvOzPzA22bWwzn3RrTLJlJfqhGIiCQ59RGIiCQ5\nBYGISJJTEIiIJDkFgYhIklMQiIgkOQWBiEiSUxCIiCQ5BYGISJL7/+ZN+TELrtsZAAAAAElFTkSu\nQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x88cada0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "yhat = createForeCast(myModelTree,myData2[:,0:-1],modelEval=modelTreeEval)\n",
    "print yhat.shape\n",
    "\n",
    "srtIndex = myData2.A[:,0].argsort(0)#排个序\n",
    "\n",
    "plt.scatter(myData2.A[:,0],myData2.A[:,1],color=\"blue\",marker=\".\")\n",
    "plt.plot(myData2[:,0].A[srtIndex],yhat.A[srtIndex],color=\"red\",linestyle = \"-\")\n",
    "plt.xlabel(\"x\")\n",
    "plt.ylabel(\"y\")\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
